import {
  SET_OPEN_TYPE,
  SET_FILTER_DATA,
  SET_TITLE_VALUE,
  SET_SELECT_VALUE
} from '../actionTypes/filtersActionTypes'
import { axios } from '../../utils/axios'
// 获取当前定位城市
import { getCity } from '../../utils'

/**
 * 设置打开类型
 * @param {*} openType 打开的类型
 */
export const setOpenType = openType => {
  return {
    type: SET_OPEN_TYPE,
    payload: openType
  }
}

/**
 * 设置过滤数据
 */
export const setFilterData = () => {
  return async dispatch => {
    const { value } = getCity()
    const result = await axios.get(`houses/condition?id=${value}`)

    dispatch({
      type: SET_FILTER_DATA,
      payload: result.data.body
    })
  }
}

/**
 * 设置标题对象
 * @param {*} titleObj
 */
export const setSelectTitleObj = titleObj => {
  return {
    type: SET_TITLE_VALUE,
    payload: titleObj
  }
}

/**
 * 设置选中值
 * @param {*} value
 */
export const setSelectValue = value => {
  return {
    type: SET_SELECT_VALUE,
    payload: value
  }
}
